package org.hiucung.desktoptranslationtools

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import cafe.adriel.voyager.navigator.tab.CurrentTab
import cafe.adriel.voyager.navigator.tab.TabNavigator
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.hiucung.desktoptranslationtools.navigation.ExportTab
import org.hiucung.desktoptranslationtools.navigation.ImportTab

@Composable
@Preview
fun App() {
    MaterialTheme {

        TabNavigator(ImportTab) { navigator ->
            Scaffold(
                bottomBar = {
                    BottomNavigation(
                        backgroundColor = MaterialTheme.colorScheme.primaryContainer,
                        contentColor = MaterialTheme.colorScheme.onPrimaryContainer
                    ) {
                        BottomNavigationItem(
                            selected = navigator.current.key == ImportTab.key,
                            onClick = {
                                navigator.current = ImportTab
                            },
                            icon = {

                            },
                            label = {
                                Text(
                                    ImportTab.options.title,
                                    color = if (navigator.current.key == ImportTab.key) {
                                        MaterialTheme.colorScheme.primary
                                    } else {
                                        MaterialTheme.colorScheme.onSurfaceVariant
                                    },
                                    overflow = TextOverflow.Ellipsis,
                                    style = MaterialTheme.typography.labelLarge
                                )
                            }
                        )

                        BottomNavigationItem(
                            selected = navigator.current.key == ExportTab.key,
                            onClick = {
                                navigator.current = ExportTab
                            },
                            icon = {

                            },
                            label = {
                                Text(
                                    ExportTab.options.title,
                                    color = if (navigator.current.key == ExportTab.key) {
                                        MaterialTheme.colorScheme.primary
                                    } else {
                                        MaterialTheme.colorScheme.onSurfaceVariant
                                    },
                                    overflow = TextOverflow.Ellipsis,
                                    style = MaterialTheme.typography.labelLarge
                                )
                            }
                        )
                    }
                },

                content = { padding ->
                    Box(
                        modifier = Modifier
                            .padding(padding)
                            .fillMaxSize() // 关键点：确保填充父布局
                    ) {
                        CurrentTab()
                    }
                })

        }
    }
}
